package com.neuedu.oasystem.service.impl;
/**
 * 业务逻辑层
 */
import java.sql.Connection;
import java.util.List;

import com.neuedu.oasystem.dao.IUserDao;
import com.neuedu.oasystem.dao.impl.UserDaoImpl;
import com.neuedu.oasystem.entity.Users;
import com.neuedu.oasystem.service.UserService;
import com.neuedu.oasystem.util.DBHelper;
/**
 * 
 * @author admin
 *
 */
public class UserServiceImpl implements UserService {
	private IUserDao userDao;

	public UserServiceImpl() {
		super();
		this.userDao = new UserDaoImpl();
	}

	@Override
	public boolean add(Users param) {
		// jdbc事务控制需要是实现Connection连接的共享，需要在业务层管理
		Connection connection = DBHelper.openConnection();
		try {
			//开始数据库事务
			connection.setAutoCommit(false);
			
			userDao.setConnection(connection);
			boolean ret = userDao.add(param);
			
			connection.commit();
			connection.setAutoCommit(true);
			return ret;
		} catch (Exception e) {
			if(connection!=null) {
				try {
					connection.rollback();
					connection.setAutoCommit(true);
				} catch (Exception e2) {
				}	
			}
		} finally {
			// jdbc事务控制需要是实现Connection连接的共享，需要在业务层管理关闭
			DBHelper.closeAll(null, null, connection);
		}
		return false;
	}

	@Override
	public boolean edit(Users param) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean deleteById(int id) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public Users findById(int id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Users> findAll() {
		// jdbc事务控制需要是实现Connection连接的共享，需要在业务层管理
		Connection connection = DBHelper.openConnection();
		try {
			userDao.setConnection(connection);
			List<Users> list = userDao.findAll();
			return list;
		} catch (Exception e) {

		} finally {
			// jdbc事务控制需要是实现Connection连接的共享，需要在业务层管理关闭
			DBHelper.closeAll(null, null, connection);
		}

		return null;
	}

	@Override
	public List<Users> findByExample(Users param) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Users> findByPager(int page, int size) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int deleteByIds(int[] ids) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int addAll(List<Users> useparamrs) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int editAll(List<Users> param) {
		// TODO Auto-generated method stub
		return 0;
	}

}